﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;

namespace MutilLanguage_Search.Connection
{
    class Office
    {
        public static List<String> GetSynonyms(String SearchText)
        {
            Microsoft.Office.Interop.Word.Application APP = new Microsoft.Office.Interop.Word.Application();
            List<String> list = new List<string>();
            try
            {
                // Initializing the language object from the Ms word Api 
                object languageID = Microsoft.Office.Interop.Word.WdLanguageID.wdEnglishAUS;
                //This object takes word and language as input and get the synonyms of it
                SynonymInfo syninfo = APP.get_SynonymInfo(SearchText, ref languageID);
                // getting the array of synonyms from the syninfo
                Array objsyninfo = syninfo.MeaningList as Array;
                //Adding the synonyms to the list  and checking that
                // same words not repeat in the list
                for (int counter = 1; counter <= objsyninfo.Length; counter++)
                {
                    String syn = objsyninfo.GetValue(counter).ToString();
                    if (!list.Contains(syn))
                    {
                        list.Add(syn);
                    }
                }

            }
            catch
            {
            }
            object nullObject = Type.Missing;
            ((_Application)APP).Quit(ref nullObject,
                                     ref nullObject,
                                     ref nullObject);
            return list;
        }
    }
}
